<template lang="pug">
  .container.lession__main
    .row.content__head
      .col-sm-3
        h2.side__menu__textbook 课本
        .side__menu__switch(@click="selectBook")
          i.icon
          | 切换
      .col-sm-9
        h2.content__filter__title 内容
          small （共2345个资源）
        .content__filter
          .content__filter__date 2017.9.12-2017.9.12
          .content__filter__order 时间顺序
      .col-sm-12
        .split
    .row
      .col-sm-3
        h3.side__menu__dt 高二课本
        ul.side__menu__list
          li(v-for="item in books", v-if="item.level === 1")
            router-link.side__menu__sub.expand(:to="'/student/lession/' + item.catalogId") {{item.catalogName}}
            ul(v-for="level2 in books", v-if="level2.level === 2")
              li
                router-link.side__menu__sub(:to="'/student/lession/' + level2.catalogId") {{level2.catalogName}}
                ul(v-for="level3 in books", v-if="level3.level === 3 && level3.parentId === level2.catalogId")
                  li
                    router-link(:to="'/student/lession/' + level3.catalogId") {{level3.catalogName}}
      .col-sm-9
        .lession__list__container
          .lession__list
            .lession__layout(v-for="item in lessions.list", @click="toDetail(item)")
              .lession__card
                .lession__video
                .lession__content
                  h5 {{item.id}}
                  table.lession__desc
                    tr
                      td {{item.teacherName}}
                        span.time.active （{{item.createdTime}}）
                  .info 
                    span {{item.playCount}}
                    span {{item.praiseCount}}
        page
</template>
<style lang="scss">
.lession__list {
  margin-right: -20px;
  @include clearfix();
}
.lession__list__container {
  margin-top: 15px;
}
.lession__layout {
  float: left;
  width: 25%;
  padding-right: 20px;
  margin-bottom: 20px;
}
.lession__card {
  background: #f2f3f5;
  
}
.lession__content {
  padding: 0 12px;
  h5 {
    margin: 10px 0;
    font-size: 16px;
  }
  .info {
    padding: 10px 0;
    font-size: 12px;
    color: #828080;
    span {
      margin-right: 5px;
    }
  }
}
.lession__desc {
  height: 28px;
  margin: 0;
  font-size: 12px;
  color: #828080;
  border-top: 1px solid #bab9ba;
  border-bottom: 1px solid #bab9ba;
  span {
    display: inline-block;
    margin-left: 3px;
    &.active {
      color: #fff;
      line-height: 24px;
      border-radius: 24px;
      background: $mainColor;
    }
  }
}
.lession__video {
  height: 190px;
}
</style>

<script>
import api from 'api/lession'
export default {
  data () {
    return {
      books: [],
      lessions: []
    }
  },
  beforeRouteEnter (to, from, next) {
    api.getLessions({
      parentcatelogid: to.params.catelogid || 1,
      from: 0,
      size: 10
    }).then((response) => {
      next(vm => {
        vm.lessions = response.data.data
      })
    })
  },
  beforeRouteUpdate (to, from, next) {
    this.getLessions({
      parentcatelogid: to.params.catelogid || 1,
      from: 0,
      size: 10
    }).then(() => {
      next()
    })
  },
  mounted () {
    this.getBooks()
  },
  methods: {
    getBooks () {
      api.getBooks('119907809079853056').then((response) => {
        this.books = response.data.data
      })
    },
    selectBook () {
      this.$store.commit('switchLession', true)
    },
    getLessions (params) {
      return api.getLessions(params).then((response) => {
        this.lessions = response.data.data
      })
    },
    toDetail (item) {
      this.$router.push('/student/lession/' + this.$route.params.catelogId + '/' + item.id)
    }
  }
}
</script>

